﻿using System.Collections.Generic;
using System.Xml.Serialization;

namespace HuaCheng.Model
{
    /// <summary>
    /// 校准因子类型
    /// </summary>
    public enum FactorName
    {
        VolFactor,
        CurFactor
    }
    /// <summary>
    /// 存储校准因子的校准数据,定义校准因子变量
    /// </summary>
    public class Factor
    {
        private double showb;
        //显示b(sb)
        [XmlAttribute("sb")]
        public double Showb
        {
            get { return showb; }
            set { showb = value; }
        }
        private double showk;
        //显示k (sk)
        [XmlAttribute("sk")]
        public double Showk
        {
            get { return showk; }
            set { showk = value; }
        }

        private double controlb;
        // 控制b(cb)
        [XmlAttribute("cb")]
        public double Controlb
        {
            get { return controlb; }
            set { controlb = value; }
        }

        private double controlk;
        // 控制k(ck)
        [XmlAttribute("ck")]
        public double Controlk
        {
            get { return controlk; }
            set { controlk = value; }
        }

        private double lowerLimit;
        // 下限
        [XmlAttribute("valuedown")]
        public double LowerLimit
        {
            get { return lowerLimit; }
            set { lowerLimit = value; }
        }
        private double upperLimit;
        // 上限
        [XmlAttribute("valueup")]
        public double UpperLimit
        {
            get { return upperLimit; }
            set { upperLimit = value; }
        }
        public Factor()
        {

        }
    }
    /// <summary>
    /// 校准因子列表
    /// </summary>
    public class FactorList
    {
        public FactorList()
        {

        }

        [XmlElement("kb")]
        public List<Factor> list = new List<Factor>();

        public Factor this[int index]
        {
            set { list[index] = value; }
            get { return list[index]; }
        }
    }
    /// <summary>
    /// 某一通道和某种因子类型对应的校准因子表
    /// </summary>
    public class ChannCalibrate
    {
        public ChannCalibrate(int index)
        {
            this.index = index;

        }

        public ChannCalibrate() { }

        private int index;
        // 设备通道索引
        [XmlAttribute("channelNum")]
        public int Index
        {
            get { return index; }
            set { index = value; }
        }
        [XmlElement("kbv")]
        public FactorList VolFactors = new FactorList();
        [XmlElement("kbc")]
        public FactorList CurFactors = new FactorList();
        public FactorList this[FactorName factorName]
        {
            set
            {

            }
            get
            {
                switch (factorName)
                {
                    case FactorName.VolFactor:
                        return VolFactors;
                    case FactorName.CurFactor:
                        return CurFactors;
                }
                return null;
            }
        }
    }
    /// <summary>
    /// ChannCalibrate列表
    /// </summary>
    public class ChannelCalibrates
    {
        int channelIndex;
        //[XmlAttribute("channelId")]
        public int ChannelIndex
        {
            get { return channelIndex; }
            set { channelIndex = value; }
        }

        [XmlArray("channels"), XmlArrayItem("channel")]
        public List<ChannCalibrate> list = new List<ChannCalibrate>();

        public void Init()
        {
            for (int i = 0; i < 8; i++)
            {
                list.Add(new ChannCalibrate() { Index = i });
            }
        }
    }
}
